package com.xidian.GMS.service.impl;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xidian.GMS.dto.Page;
import com.xidian.GMS.entity.EmploymentConsult;
import com.xidian.GMS.entity.JobFair;
import com.xidian.GMS.mapper.AnnouncementMapper;
import com.xidian.GMS.mapper.JobFairMapper;
import com.xidian.GMS.entity.JobFair;
import com.xidian.GMS.service.JobFairService;
@Service
public class JobFairServiceImpl implements JobFairService {
	@Autowired
	private JobFairMapper jobFairMapper;
	
	@Override
	public JobFair Insert(JobFair jobFair) {
		  Date date =  jobFair.getStarttime();
		  System.out.println(date);
		  System.out.println(jobFair);
		 
	   	  int rows = jobFairMapper.insert(jobFair);
			if( jobFair == null ||rows == 0){
				throw new RuntimeException("错误");
			}
	          return jobFair;
	    }

	@Override
	public boolean delete(int JobFairid) {
        int x =  jobFairMapper.deleteByPrimaryKey(JobFairid);
  	  if (x == 1) {
  	  	  return true;
	}
          return false;
    }	
	@Override
	public boolean update(int jobFairid,String jobFairName, String starttime, String organizer, String jobFairLocation,
			String jobFairContent)  {
		// TODO Auto-generated method stub
		   JobFair jobFair2 = jobFairMapper.selectByPrimaryKey(jobFairid);
			
			jobFair2.setJobFairName(jobFairName);;
	    	try {
				jobFair2.setStarttime(starttime);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    	jobFair2.setOrganizer(organizer);
	    	jobFair2.setJobFairLocation(jobFairLocation);
        int temp = jobFairMapper.updateByPrimaryKeySelective(jobFair2);
		
    	  if (temp == 1) {
   	  	  return true;
 	}
           return false;
     }
	@Override
	public Page getJobFair(int cur) {
		Page page = new Page(cur);
		
		int count = jobFairMapper.count();
		
		List<JobFair> accounts = jobFairMapper.findAll(page.getOffset(), page.getSize());
		
		page.setCount(count);
		page.setList(accounts);
		
		return page;
	}
}
